export const directives = (app: any) => {
    // 自定义指令防抖
    app.directive('debounce', {
        // mounted生命周期
        mounted(el: any, binding: any) {
            // 判断是否为方法
            if (typeof binding.value !== 'function') return
            el.timer = null

            el.handler = function () {
                // 计时器存在(清除)
                if (el.timer) clearTimeout(el.timer)

                el.timer = setTimeout(() => {
                    binding.value.apply(this, arguments)
                },600)
            }
            el.addEventListener('click', el.handler)
        },
        // 销毁前 生命周期
        beforeUnmount(el: any, binding: any) {
            // 回复timer和清空计时器
            if (el.timer) {
                el.timer = null
                clearTimeout(el.timer)
            }
            // 取消点击事件
            el.removeEventListener('click', el.handler)
        }
    })
}

export const common = {
    sex: function(type: any) {
        if (type == 1 ) return '男'
        else if(type == 2) return '女'
    }
} 